<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */
class ChangePasswordForm extends CFormModel {

    public $oldpassword;
    public $newpassword;
    public $newpassword_repeat;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            array('oldpassword,newpassword,newpassword_repeat', 'required', 'message' => 'Pole wymagane'),
            array('newpassword', 'length', 'min' => 8, 'tooShort' => 'Minimalna ilośc znaków to 8'),
            array('newpassword', 'compare', 'compareValue' => $this->newpassword, 'message' => 'Powtórzone hasło jest inne niż nowe'),
            //array('oldpassword', 'exist', 'attributeName' => 'pass_hash', 'className' => ),
        );
    }
            
    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'oldpassword' => 'Stare hasło',
            'newpassword' => 'Nowe hasło',
            'newpassword_repeat' => 'Powtórz nowe hasło'
        );
    }
    
    public function changePassword($id, $worker){
        return Yii::app()->db->createCommand("SELECT changepasswordfun('".$id."','".md5($this->oldpassword)."','".md5($this->newpassword)."','".md5($this->newpassword_repeat)."','".$worker."')")->execute();
    }


}
